#
# Web server configuration module
#
# make a copy of this file and customize that for your work
#
#
# attributes that must always be present are capitalized
#
import atlas, sys
import functools

root = 'NIMBRAT'
tag  = 'kevin'
organism = 'yeast'

#
# displayed on the index page
#
TITLE = "Nucleosome Reconstitution"

#
# directory setup, a string containing the 
# full path to a directory 
#
home = atlas.ENV.HOME_DIR # default location

#
# typically these directories do not need to be altered
#
TEMPLATE_DIR = home + "/html"
SESSION_DIR  = home + "/html/session"
STATIC_DIR   = home + "/html/static"
DOWNLOAD_DIR = home + "/html/static/download"
IMAGE_DIR    = home + "/html/static/img"
STATIC_URL   = "/static"

#
# database setup
#

HDF_DATABASE = "%s/db/%s-%s.hdf" % (home, tag, organism)
SQL_URI = "sqlite:///%s/db/%s-%s.sqlite" % (home, tag, organism)

#
# the value of the CHROM_FIELDS could be hardcoded as a list of tuples
# but it is more reliable if we dynamically generate it from a HDF file
#
root='GERALD'
try:
    from atlas import hdf
    db = hdf.hdf_open( HDF_DATABASE, mode='r' )
    data = hdf.GroupData(db=db, name=root)
    chromosomes = data.labels
    db.close()
except Exception, exc:
    atlas.error("unable to read chromosomes %s" % exc )
    sys.exit()
    
#
# used to generate the chromosome dropdown menu
#
CHROM_FIELDS = [ (x, x) for x in chromosomes ]

#
# used to generate the zoom dropdown menu
#
LEVELS      = [ 50, 100, 250, 500, 1000, 2500, 5000, 10000, 20000, 50000, 100000, 200000 ]
LEVELS      = map(str, LEVELS)
humanized   = map(atlas.commify, LEVELS)
ZOOM_LEVELS = [ (x, y) for x,y in zip(LEVELS, humanized) ]

#
# generates the dropdown menu for the plot
# first element is the key the second the visible menu item
# keys must map to the PLOT_MAPPER
#


#
# the main plotbuilder
#
from recon.trackbuilder import build_tracks

#
# customizing the plotbuilder via partial application

#
# composite tracks
#
root = 'GERALD'
gerald_medres_composite_tracks = functools.partial ( build_tracks, 
        data_label = root, 
        fit_label  = '%s-SIGMA-20' % root, 
        pred_label = 'PRED-%s-SIGMA-20' % root, 
        strand     = 'composite' )

gerald_hires_composite_tracks = functools.partial ( build_tracks, 
        data_label = root, 
        fit_label  = '%s-SIGMA-5' % root, 
        pred_label = 'PRED-%s-SIGMA-5' % root, 
        strand     = 'composite' )


#
# for twostrand tracks
#
gerald_medres_twostrand_tracks = functools.partial ( build_tracks, 
        data_label = root, 
        fit_label  = '%s-SIGMA-20' % root , 
        pred_label = 'PRED-%s-SIGMA-20' % root, 
        strand     = 'twostrand' )

gerald_hires_twostrand_tracks = functools.partial ( build_tracks, 
        data_label = root, 
        fit_label  = '%s-SIGMA-5' % root , 
        pred_label = 'PRED-%s-SIGMA-5' % root, 
        strand     = 'twostrand' )


root = 'NIMBRAT'
nimble_medres_composite_tracks = functools.partial ( build_tracks, 
        data_label = root, 
        fit_label  = '%s-SIGMA-20' % root, 
        pred_label = 'PRED-%s-SIGMA-20' % root, 
        strand     = 'composite' )

nimble_hires_composite_tracks = functools.partial ( build_tracks, 
        data_label = root, 
        fit_label  = '%s-SIGMA-15' % root, 
        pred_label = 'PRED-%s-SIGMA-15' % root, 
        strand     = 'composite' )


#
# the plotmapper connects the plot choice to a template and a track layout
#
PLOT_CHOICES = [ 
    ('nimble-composite-medres', 'Nimblegen Composite Medium'), 
    ('nimble-composite-hires' , 'Nimbledgen Composite Hires'), 
    ('gerald-composite-medres', 'Solexa Composite Medium'), 
    ('gerald-composite-hires' , 'Solexa Composite Hires'), 
    ('gerald-twostrand-medres', 'Solexa Two Stranded Medium'),
    ('gerald-twostrand-hires' , 'Solexa Two Stranded HiRes'),
 
]

PLOT_MAPPER = {
    'gerald-composite-medres': ( 'index.html', gerald_medres_composite_tracks ),
    'gerald-composite-hires' : ( 'index.html', gerald_hires_composite_tracks ),
    'nimble-composite-medres': ( 'index.html', nimble_medres_composite_tracks ),
    'nimble-composite-hires' : ( 'index.html', nimble_hires_composite_tracks ),
    'gerald-twostrand-medres': ( 'index.html', gerald_medres_twostrand_tracks ),
    'gerald-twostrand-hires' : ( 'index.html', gerald_hires_twostrand_tracks ),
}

#
# a sanity check to catch errors early on
#
for key, value in PLOT_CHOICES:
    assert key in PLOT_MAPPER, "Key '%s' not found in PLOT_MAPPER" % key

#
# socket related configuration
#
SOCKET_PORT = 8080
SOCKET_HOST = "localhost"
THREAD_POOL = 10
